#pytest配置fixture文件

from playwright.sync_api import sync_playwright
import pytest
from utils.logger import log

@pytest.fixture(scope="class", autouse=True)
def context():
    #初始化
    playwright = sync_playwright().start()
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    log.debug("浏览器启动成功")

    #返回上下文
    yield context

    #关闭释放服务
    context.close()
    browser.close()
    playwright.stop()
    log.debug("浏览器关闭成功")

